package algotradingfx.backtesting;

import algotradingfx.utils.Constants;
import algotradingfx.utils.FXAsset;
import atp.client.trading.methods.TradingMethod.Side;
import atp.client.trading.methods.TradingMethod.Type;
import atp.client.trading.strategies.Strategy;
import atp.client.trading.strategies.StrategyPush;
import atp.commons.util.StrategyInfo;
import atp.commons.util.Tick;

public class MockStrategy extends StrategyPush implements Strategy {

	private static final long serialVersionUID = -6184070147002939763L;
	private static final String STRATEGY_NAME = "MockStrategy";
	private boolean hasRunOnce;
	private StrategyAction action;
	private String lastTicket;

	public MockStrategy() {
		super(new StrategyInfo(STRATEGY_NAME), Constants.SSID, Constants.PASSWORD);
		hasRunOnce = false;
	}

	@Override
	public void initialise() {
	}

	@Override
	public boolean run(Object o) {
		if (hasRunOnce)
			return false;

		if (o instanceof Tick) {
			Tick t = (Tick) o;
			if (action.equals(StrategyAction.BUY)) {
				lastTicket = forex.send(FXAsset.EURUSD.toString(), Type.MARKET, Side.BUY, t.getAskDepth(), 0.0, 0.0,
				        Constants.MOCK_BROKER);
				hasRunOnce = true;
			}
		}
		return false;
	}

	public void setBuyStrategy() {
		action = StrategyAction.BUY;
	}

	public void setSellStrategy() {
		action = StrategyAction.SELL;
	}

	public String getLastTicket() {
		return lastTicket;
	}

	private enum StrategyAction {
		BUY, SELL;
	}
}
